package com.lai.shop.controller;



import java.util.Arrays;
import java.util.Map;

import com.lai.shop.utils.PageUtils;
import com.lai.shop.utils.R;
import com.lai.shop.vo.OrderSubmitVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.lai.shop.entity.OrderEntity;
import com.lai.shop.service.OrderService;

import javax.servlet.http.HttpSession;


/**
 * 订单表
 *
 * @author laiciqi
 * @email 602469238@qq.com
 * @date 2022-05-19 13:16:53
 */
@RestController
@RequestMapping("/order")
@Api(value = "订单模块",tags = "订单模块")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 列表
     */
    @ApiOperation(value = "分页查看所有订单列表")
    @ApiImplicitParam(name = "params", value = "查询参数", required = true)
    @RequestMapping("/list")
    //@RequiresPermissions(":order:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation(value = "根据id查询订单信息")
    @ApiImplicitParam(name = "id", value = "订单id", required = true)
    @RequestMapping("/info/{id}")
    //@RequiresPermissions(":order:info")
    public R info(@PathVariable("id") Long id){
		OrderEntity order = orderService.getById(id);

        return R.ok().put("order", order);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "保存订单")
    @ApiImplicitParam(name = "order", value = "订单实体", required = true,dataType = "OrderEntity")
    @RequestMapping("/save")
    //@RequiresPermissions(":order:save")
    public R save(@RequestBody OrderEntity order){
		orderService.save(order);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改订单信息")
    @ApiImplicitParam(name = "order", value = "订单实体", required = true,dataType = "OrderEntity")
    @RequestMapping("/update")
    //@RequiresPermissions(":order:update")
    public R update(@RequestBody OrderEntity order){
		orderService.updateById(order);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "批量删除")
    @ApiImplicitParam(name = "ids", value = "需要删除的id", required = true)
    @RequestMapping("/delete")
    //@RequiresPermissions(":order:delete")
    public R delete(@RequestBody Long[] ids){
		orderService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    @ApiOperation(value = "批量删除")
    @ApiImplicitParam(name = "orderSubmitVo", value = "订单提交需要的数据", required = true)
    @PostMapping("/submitOrder")
    public R submitOrder(@RequestBody OrderSubmitVo orderSubmitVo, HttpSession session){
        orderService.saveOrder(orderSubmitVo,session);
        return R.ok();
    }

}
